<script>
    //复杂计算，限制最长执行时间
    function complexCalc(millseconds) {
        return new Promise((resolve, reject) => {
            if (millseconds < 0) {
                throw new Error("操作时间必须大于0");
            }
            else if (millseconds < 1000) {
                reject("操作时间必须大于1000");  //失败时回调
            } else {
                setTimeout(() => {
                    resolve(Math.random() * 1000);  //成功时回调
                }, millseconds);
            }
        });
    }
    complexCalc(-1).catch(error=>{
        console.log(error)
    });
    complexCalc(0).catch(error=>{
        console.log(error)
    });
    complexCalc(1895).then(data=>{
        console.log(data)
    });
</script>